import type { Station } from "@/pages/station/stationList/services";
import request from "@/utils/request";
import request2 from "@/utils/request2";
import { CategoryState, CategoryType } from "@/constants/enums/category"

export interface CityData extends ChartValue {
  children: CityData[]
}

export async function queryCityOptions() {
  return request<CityData[]>('/app/manager/user/cityData')
}

export async function queryStationOptions() {
  return request<Station[]>('/app/station/stationList/options')
}

export async function queryCityOptions2(token?: string) {
  return request<CityData[]>('/app/manager/user/cityData', {token})
}

export async function queryCityOptions2WithOutD() {
  return request2('/app/manager/user/cityData', {
    method: 'POST',
    data: {loginType:1},
  })
}

export async function fileUp(params: FormData) {
  return request<string>(`/app/user/fileUp`, {
    method: 'POST',
    data: params,
  })
}

/**
 * 获取菜单类型
 */
export enum MenuAll {
  平台所有菜单 = 1,
  大客户所有菜单 = 2,
  大客户可见菜单 = 3,
  平台可见菜单 = 0, // 接口传递 undefined
}
export type GetMenuParams = {
  all?: MenuAll
}
export async function getMenu(params: GetMenuParams, token?: string) {
  // return menuData
  return request<OriginMenu[]>('/app/manager/menu', {
    data: {
      // userId: localStorage.userId,
      all: params?.all ? params.all : undefined,
    },
    token,
  })
}

export async function queryWaitExcuseCount() {
  return request<WaitExcuseCount>('/app/manager/waitExcuseCount', {data: {}})
}

export async function editPsd(params: {old: string, password: string}) {
  return request('/app/manager/user/changePass', {
    data: params,
  })
}

export async function choosePlat(params: {platId: string}) {
  return request<{token: string}>('/app/manager/plat/choose', {
    data: params,
  })
}

export async function chooseCompany(params: {companyId: string}) {
  return request<{token: string}>('/app/manager/company/choose', {
    data: params,
  })
}

export async function queryCategory(params: {state?: CategoryState, type?: CategoryType}) {
  return request2<Category[]>('/api/mall/manage/category', {
    method: 'GET',
    data: params,
  })
}

export async function saveCategory(params: Partial<Category>) {
  return request2('/api/mall/manage/category', {
    method: 'POST',
    data: params,
  })
}

export async function removeCategory(params: {categoryId: string}) {
  return request2(`/api/mall/manage/category/${params.categoryId}`, {
    method: 'DELETE',
  })
}

export async function configExcelUp(params: FormData) {
  return request<string>(`/app/manager/equipment/proportion/cfg`, {
    method: 'POST',
    data: params,
  })
}

export async function pinExcelUp(params: FormData) {
  return request<string>(`/app/manager/equipment/proportion/pin`, {
    method: 'POST',
    data: params,
  })
}

export async function getGoodsStock(id: string) {
  return request2<string>(`/api/mall/manage/goods/stock/${id}`, {
    method: 'GET',
  })
}
